package com.atguigu.dao.impl;

import com.atguigu.dao.DeployEnvDao;
import com.atguigu.pojo.DeployEnv;
import com.atguigu.pojo.MysqlServiceConfig;

import java.util.List;


public class DeployEnvDaoImpl extends BaseDao implements DeployEnvDao {

    @Override
    public int addDeployEnv(DeployEnv deployEnv) {
        System.out.println("DeployEnvDaoImpl程序在[" + Thread.currentThread().getName() + "]线程中");
        String sql = "insert into t_deployEnv(`id`,`name`) values(?,?);";
        return update(sql,deployEnv.getId(),deployEnv.getName());
    }

    @Override
    public int deleteDeployEnvById(String id) {
        String sql = "delete from t_deployEnv where id=?";
        return update(sql, id);
    }
    @Override
    public int updateDeployEnv(DeployEnv deployEnv) {
        String sql="update t_deployEnv set `name`=? where id=?";
        return update(sql,deployEnv.getName(),deployEnv.getId());
    }
    @Override
    public DeployEnv queryDeployEnvById(String id) {
        String sql ="select `id`,`name` from t_deployEnv where id=?";
        return queryForOne(DeployEnv.class,sql,id);
    }
  
    @Override
    public List<DeployEnv> queryDeployEnvs() {// 查询全部
        String sql = "select `id`,`name` from t_deployEnv";
        return queryForList(DeployEnv.class, sql);
    }

    @Override
    public Integer queryForPageTotalCount() {//查询总条目数,为page分片做准备
        String sql = "select count(*) from t_deployEnv";
        Number deployEnvCount = (Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return deployEnvCount.intValue();
    }

    @Override
    public List<DeployEnv> queryForPageItems(Integer begin, Integer pageSize) {
        String sql = "select `id`,`name` from t_deployEnv limit ?,?";
        return queryForList(DeployEnv.class, sql, begin, pageSize);//查询数据片段
    }
}


